package com.ms.service.module.zone.command;

import com.ms.game.common.container.LevelInfoBinUtil;
import com.ms.player.Player;
import com.ms.player.PlayerAttributeType;
import com.ms.player.UpdateAttributeList;
import com.ms.service.module.zone.module.BasicZoneModule;

public class LevelUpCommand extends BasicDebugCommand {
	
	@Override
	public String execute() {

		if (commandValue == null) {
			return getDescription();
		}

		if (commandValue.length >= 2) {
			String levelstr = commandValue[1];
			if (levelstr == null) {
				return getDescription();
			}
			
			int level = Integer.valueOf(levelstr);
			if(level <= 0){
				return getDescription();
			}
			
			BasicZoneModule module = getModule();
			if (module == null) {
				return "can't get current module.";
			}

			Player player = getPlayer();
			player.setLevel(player.getLevel() + level);
			player.setExp(LevelInfoBinUtil.getExpByLevel(0, player.getLevel()));
			
			UpdateAttributeList updateList = new UpdateAttributeList();
			updateList.addUpdateValue(PlayerAttributeType.LEVEL, player.getLevel());
			updateList.addUpdateValue(PlayerAttributeType.EXP, player.getExp());
			
			// 等級更變消息
			player.sendUpdatedAttrToClient();
			// DC等級更變
			boolean res = module.getPlayerDataAgent().updatePlayerDataToDC(player, updateList, "");

			return (res ? "ok" : "fail");
			
		}

		return getDescription();
	}

	@Override
	public String getName() {
		return "addlv";
	}

	@Override
	public String getDescription() {
		return "addlv [+level]       (add number of level)";
	}

	@Override
	public String getShortDescription() {
		return "addlv [level]";
	}

}
